package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;


import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.query.QuestionPageQuery;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author yang
 * @since 2024-06-25
 */
@RestController
@Api(tags = "问题相关接口")
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;


    @PostMapping()
    @ApiOperation("新增问题")
    void addQuestion(@Valid @RequestBody QuestionFormDTO question) {
        interactionQuestionService.addQuestion(question);
    }

    @GetMapping("/page")
    @ApiOperation("问题分页查询")
    PageDTO<QuestionVO> pageGetQuest(QuestionPageQuery query){
        return interactionQuestionService.pageGetQuest(query);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    QuestionVO getQuestionById(@PathVariable("id") Long id){
        return interactionQuestionService.getQuestionById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改问题")
    void updateQuestion(@PathVariable("id") Long id, @RequestBody QuestionFormDTO question){
        interactionQuestionService.updateQuestion(question, id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除问题")
    void deleteQuestion(@PathVariable("id") Long id){
        interactionQuestionService.deleteQuestion(id);
    }


}
